
import axios from "axios"


import  {useDispatch} from "react-redux"
import { getUserRoutesThunk } from "../../store/userinfo"
import { useNavigate } from "react-router-dom"
let account = ""
let password = ""
function Login(){
    let nav = useNavigate()
    let dispatch = useDispatch()
    const login = ()=>{
        axios.post("http://192.168.137.1:8001/login",{account,password}).then((res)=>{
            let data = res.data
            if(data.msg === "登录成功"){
                let id = data.id
                dispatch(getUserRoutesThunk(id))
                nav("/page3")
            }else{
                alert("登录失败")
            }
        })
        
    }

    return <>
        <div>账号:<input type = "text" onChange={(e)=>{account = e.target.value}}></input></div>
        <div>密码:<input type = "text" onChange={(e)=>{password = e.target.value}}></input></div>
        <button onClick={login}>登录</button>
    </>
}


export default Login